from multiprocessing import Process,Event
import time
import random

def trafficLight(e):
	'''信号灯函数'''
	while 1:
		if e.is_set():
			time.sleep(5)
			print('红灯亮!\n车辆等待中...')
			e.clear()
		else:
			time.sleep(5)
			print('绿灯亮!\n车辆通过中...')
			e.set()

def carStatus(num,e):
	e.wait()
	print('第%s辆车过去了'%num)

if __name__=='__main__':
	event=Event()
	traLight=Process(target=trafficLight,args=(event,))
	traLight.start()
	for i in range(50):
		if i % 3 == 0:
			time.sleep(random.randint(1,5))
		car = Process(target=carStatus,args=(i+1,event,))
		car.start()